﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;

namespace FormConsultaPadrao
{
    public partial class FormConsulta : Form
    {
        public TabPage tbpgAba;
        public string sql;

        public FormConsulta()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            tbpgAba.Dispose();
        }

        private void fecharAnexoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tbpgAba.Dispose();
        }

        private void FormConsulta_FormClosing(object sender, FormClosingEventArgs e)
        {
            tbpgAba.Dispose();
        }

        public virtual void tlstrpbtnPesquisar_Click(object sender, EventArgs e)
        {
            dtgrdvwPagina1.DataSource = Conexao.getInstance.executeQuery(sql);
            txtbxRegistros.Text = dtgrdvwPagina1.RowCount.ToString();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //if (keyData == (Keys.Control | Keys.F))
            if (keyData == (Keys.F3))
            {
                if (tlstrpbtnPesquisar.Enabled)
                {
                    tlstrpbtnPesquisar_Click(null, null);
                }
                return true;
            }
            else if (keyData == Keys.Escape)
            {
                if (tlstrpbtnLimpar.Enabled)
                {
                    tlstrpbtnLimpar_Click(null, null);
                }
            }
            else if (keyData == (Keys.Control | Keys.R))
            {
                if (tlstrpbtnRefresh.Enabled)
                {
                    tlstrpbtnRefresh_Click(null, null);
                }
            }
            else if (keyData == (Keys.Control | Keys.W))
            {
                toolStripButton1_Click(null, null);
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public virtual void tlstrpbtnLimpar_Click(object sender, EventArgs e)
        {
            
        }

        public void tlstrpbtnRefresh_Click(object sender, EventArgs e)
        {
            if (sql != null)
            {
                dtgrdvwPagina1.DataSource = Conexao.getInstance.executeQuery(sql);
                txtbxRegistros.Text = dtgrdvwPagina1.RowCount.ToString();
            }
        }

        public virtual void dtgrdvwPagina1_DataSourceChanged(object sender, EventArgs e)
        {

        }

        public virtual void dtgrdvwPagina1_SelectionChanged(object sender, EventArgs e)
        {

        }


    }
}
